package com.hu.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hu.common.annotation.Log;
import com.hu.common.core.controller.BaseController;
import com.hu.common.core.domain.AjaxResult;
import com.hu.common.enums.BusinessType;
import com.hu.system.domain.StockLoss;
import com.hu.system.service.IStockLossService;
import com.hu.common.utils.poi.ExcelUtil;
import com.hu.common.core.page.TableDataInfo;

/**
 * 库存损耗Controller
 *
 * @author hu
 * @date 2025-01-30
 */
@RestController
@RequestMapping("/business/stock/loss")
public class StockLossController extends BaseController {
    @Autowired
    private IStockLossService stockLossService;

    /**
     * 查询库存损耗列表
     */
    @PreAuthorize("@ss.hasPermi('stock:loss:list')")
    @GetMapping("/list")
    public TableDataInfo list(StockLoss stockLoss) {
        startPage();
        List<StockLoss> list = stockLossService.selectStockLossList(stockLoss);
        return getDataTable(list);
    }

    /**
     * 导出库存损耗列表
     */
    @PreAuthorize("@ss.hasPermi('stock:loss:export')")
    @Log(title = "库存损耗", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StockLoss stockLoss) {
        List<StockLoss> list = stockLossService.selectStockLossList(stockLoss);
        ExcelUtil<StockLoss> util = new ExcelUtil<StockLoss>(StockLoss.class);
        util.exportExcel(response, list, "库存损耗数据");
    }

    /**
     * 获取库存损耗详细信息
     */
    @PreAuthorize("@ss.hasPermi('stock:loss:query')")
    @GetMapping(value = "/{lossId}")
    public AjaxResult getInfo(@PathVariable("lossId") Long lossId) {
        return success(stockLossService.selectStockLossById(lossId));
    }

    /**
     * 新增库存损耗
     */
    @PreAuthorize("@ss.hasPermi('stock:loss:add')")
    @Log(title = "库存损耗", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StockLoss stockLoss) {
        return toAjax(stockLossService.insertStockLoss(stockLoss));
    }

    /**
     * 修改库存损耗
     */
    @PreAuthorize("@ss.hasPermi('stock:loss:edit')")
    @Log(title = "库存损耗", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StockLoss stockLoss) {
        return toAjax(stockLossService.updateStockLoss(stockLoss));
    }

    /**
     * 删除库存损耗
     */
    @PreAuthorize("@ss.hasPermi('stock:loss:remove')")
    @Log(title = "库存损耗", businessType = BusinessType.DELETE)
    @DeleteMapping("/{lossIds}")
    public AjaxResult remove(@PathVariable Long[] lossIds) {
        return toAjax(stockLossService.deleteStockLossByIds(lossIds));
    }
}

